Figures
head(malawi_MFL)
## # A tibble: 6 x 11
##   CODE  NAME  `COMMON NAME` OWNERSHIP TYPE  STATUS ZONE  DISTRICT `DATE OPENED`
##   <chr> <chr> <chr>         <chr>     <chr> <chr>  <chr> <chr>    <chr>        
## 1 MC01… A + … A+A           Private   Clin… Funct… Cent… Mchinji  Jan 1st 75   
## 2 BT24… A-C … A.C Opticals  Private   Clin… Funct… Sout… Blantyre Jan 1st 75   
## 3 MZ16… A-C … A-C Opticals  Mission/… Clin… Non-f… Nort… Mzimba   Jan 1st 75   
## 4 BT24… Akwe… Akwezeke Pvt  Private   Clin… Funct… Sout… Blantyre Jan 1st 75   
## 5 BT24… AB M… Abowa         Private   Clin… Funct… Sout… Blantyre Jan 1st 75   
## 6 LL04… ABC … ABC Clinic    Christia… Hosp… Funct… Cent… Lilongwe Jan 1st 75   
## # … with 2 more variables: LATITUDE <chr>, LONGITUDE <chr>
head(malawi_WHO)
## # A tibble: 6 x 10
##   Country Admin1 `Facility name` `Facility type` Ownership   Lat  Long
##   <chr>   <chr>  <chr>           <chr>           <chr>     <dbl> <dbl>
## 1 Malawi  Centr… 80 Block Clinic Clinic          MoH       -12.9  33.4
## 2 Malawi  Centr… ABC Community … Clinic          FBO       -14.0  33.7
## 3 Malawi  Centr… Adventist Heal… Health Centre   FBO       -14.0  33.8
## 4 Malawi  Centr… Alinafe Commun… Community Hosp… FBO       -13.4  34.2
## 5 Malawi  Centr… Area 18 Health… Health Centre   MoH       -13.9  33.8
## 6 Malawi  Centr… Area 25 Health… Health Centre   MoH       -13.9  33.8
## # … with 3 more variables: `LL source` <chr>, iso3c <chr>,
## #   facility_type_9 <chr>

Missing values/wrong coordinates
# MFL - 1546 before omitting NA's, then 1427.
# 62 coordinates did not intersect with admin data - now 1365

# using anti_join() to see which facilities were omitted 
df_malawi_facilities_MFL = as.data.frame(malawi_facilities_MFL) # convert to data frame to use in anti_join

NA_MFL = anti_join(malawi_MFL, df_malawi_facilities_MFL) # 119 missing coordinates in MFL

# adding the number of wrong coordinates - 61
intersect_admin1_MFL = st_intersection(malawi_facilities_MFL, malawi_admin1) # returns data frame of matches

intersect_admin1_MFL = as.data.frame(intersect_admin1_MFL) # convert to data frame to use in anti_join

no_intersect_admin1_MFL = anti_join(malawi_facilities_MFL, intersect_admin1_MFL) # working out which facilities did not intersect

no_intersect_admin1_MFL_1 = no_intersect_admin1_MFL[ ,-c(10, 11)]
NA_MFL_1 = NA_MFL[, -c(10, 11)]
no_intersect_admin1_MFL_1 = st_set_geometry(no_intersect_admin1_MFL_1, NULL)
names(NA_MFL_1)[3] = "COMMON.NAME"
names(NA_MFL_1)[9] = "DATE.OPENED"

NA_MFL = rbind(NA_MFL_1, no_intersect_admin1_MFL_1) # combined dataframe of NA and wrong coordinates in MFL

# WHO - 648 with 9 missing coordinates, now 639
NA_WHO = anti_join(malawi_WHO, new_malawi_WHO)
Proportion that are privately owned in the MFL data
private_MFL = filter(malawi_facilities_MFL, OWNERSHIP == "Private")
# 433 private facilities, 30.3%

# which types are private?
private_MFL$TYPE = as.factor(private_MFL$TYPE)
types_private_MFL = as.data.frame(table(private_MFL$TYPE))
types_private_MFL
##            Var1 Freq
## 1        Clinic  356
## 2    Dispensary   45
## 3 Health Centre    9
## 4   Health Post    1
## 5      Hospital   16
## 6       Private    6
Proportion of facility types in each district
# district per facility (does not include the 62 facilities)
intersect_admin2_MFL = st_intersection(malawi_facilities_MFL, malawi_admin2)
intersect_admin2_MFL$TYPE = as.factor(intersect_admin2_MFL$TYPE)
intersect_admin2_MFL$shapeName = as.factor(intersect_admin2_MFL$shapeName)

by_district_MFL = as.data.frame(table(intersect_admin2_MFL$TYPE, intersect_admin2_MFL$shapeName))
head(by_district_MFL)
##                Var1   Var2 Freq
## 1  Central Hospital Balaka    0
## 2            Clinic Balaka   10
## 3        Dispensary Balaka    1
## 4 District Hospital Balaka    1
## 5     Health Centre Balaka   11
## 6       Health Post Balaka    4
# pie charts for each district 
balaka_MFL = filter(by_district_MFL, Var2 == "Balaka")
balaka_MFL = filter(balaka_MFL, Freq > 0)
balaka_MFL = balaka_MFL[ , -c(2)]

## plot
balaka_plot_MFL = sunburst(balaka_MFL)
balaka_plot_MFL
Legend